package com.lishe.lishe.lishe.module.me.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.base.BaseActivity;

/**
 * Created by zhcasecom on 2017/8/21.
 */

public class AboutActivity extends BaseActivity {
    private static String url;
    String title;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about_lishe);
        title=getIntent().getStringExtra("title");
        url=getIntent().getStringExtra("url");
        init();

    }


    private void init() {
        WebView webView = (WebView) findViewById(R.id.webview);

        webView.setWebViewClient(new WebViewClientImpl());
        //支持javascript
        webView.getSettings().setJavaScriptEnabled(true);
        // 设置可以支持缩放
        webView.getSettings().setSupportZoom(false);
        // 设置出现缩放工具
        webView.getSettings().setBuiltInZoomControls(false);
        //扩大比例的缩放
        webView.getSettings().setUseWideViewPort(false);
        //自适应屏幕

        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);


        webView.getSettings().setLoadWithOverviewMode(true);
        webView.loadUrl(url);
        TextView titletxt = findViewById(R.id.title_text_title);
        titletxt.setText(title);
        Button back = findViewById(R.id.title_left_button);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    public static void jump(Activity activity,String title,String url) {
        Intent intent = new Intent(activity, AboutActivity.class);
        intent.putExtra("title",title);
        intent.putExtra("url",url);
        activity.startActivity(intent);
    }

    class WebViewClientImpl extends WebViewClient {

        //重写shouldOverrideUrlLoading方法，使点击链接后不使用其他的浏览器打开。

        @Override

        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            view.loadUrl(url);

            //如果不需要其他对点击链接事件的处理返回true，否则返回false

            return true;

        }


    }
}
